package com.zb.service.impl;

import com.zb.service.GeneratorStatusService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class RedisGeneratorStatusServiceImpl implements GeneratorStatusService {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Value("${data-generator.redis-status-key}")
    private String statusKey;

    @Override
    public void setGenerating(boolean isGenerating) {
        redisTemplate.opsForValue().set(statusKey, isGenerating ? "1" : "0");
    }

    @Override
    public boolean isGenerating() {
        String status = redisTemplate.opsForValue().get(statusKey);
        return "1".equals(status);
    }

    @Override
    public void resetStatus() {
        redisTemplate.delete(statusKey);
    }
}
